<?php

class User_Form_CompleteProfileForm extends Ac_Form
{
    /**
     *
     * @var Model_User empty user with properly setted behavior
     */
    private $_user;

    function setUser($user)
    {
        $this->_user = $user;
    }
    
    public function init()
    {
        parent::init();
        if (empty($this->_user->username)) {
            $this->addElement('text', 'username', array(
                'filters'    => array('StringTrim', 'StringToLower'),
                'validators' => array(
                    'Username'
                ),
                'required'   => false,
                'label'      => 'Your username:',
            ));
        }

        if (empty($this->_user->email)) {
            $this->addElement('text', 'email', array(
                'filters'    => array('StringTrim', 'StringToLower'),
                'validators' => array(
                    'EmailAddress',
                ),
                'required'   => false,
                'label'      => 'Your email:',
            ));
        }

        if (empty($this->_user->phone)) {
            $this->addElement('text', 'phone', array(
                'filters'    => array('StringTrim', 'StringToLower'),
                'validators' => array(
                ),
                'required'   => false,
                'label'      => 'Your phone:',
            ));
        }

        $login = $this->addElement('submit', 'login', array(
            'required' => false,
            'ignore'   => true,
            'label'    => 'Validate',
        ));
    }

    /**
     *
     *
     * let's login the user based on provided bahavior
     *
     */
    public function save()
    {

        $this->_user->phone = $this->getValue('phone');
        $this->_user->save();
    }
}

